package com.leo.springbootmultithreadbasic.threadpool;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Leo
 * @version V1.0
 */
public class MyThreadFactory2 implements ThreadFactory {

    private final String namePrefix;

    private final AtomicInteger threadNo = new AtomicInteger(1);

    MyThreadFactory2(String threadFactoryName) {
        namePrefix = "From MyThreadFactory's " + threadFactoryName + "-Worker-";
    }


    @Override
    public Thread newThread(Runnable task) {
        // thread name: Prefix&ThreadNo
        String threadName = namePrefix + threadNo.getAndIncrement();
        return new Thread(task, threadName);
    }
}
